:: in php

33

/*
The Scope Resolution Operator (also called Paamayim Nekudotayim) 
or in simpler terms, the double colon, is a token that allows 
access to static, constant, and overridden properties or methods 
of a class.
*/
class MyClass {
    const CONST_VALUE = 'A constant value';
}

$classname = 'MyClass';
echo $classname::CONST_VALUE;

echo MyClass::CONST_VALUE;
/*
This is an easy way to execute conditional html / 
javascript / css / other language code with 
php if else:

No need for curly braces {}
*/
<?php if (condition): ?>

// html / javascript / css / other language code to run if condition is true

<?php else: ?>

// html / javascript / css / other language code to run if condition is false

<?php endif ?>

Comments

Submit
0 Comments